package top.heliming.youyou.item.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.heliming.youyou.item.dao.CategoryMapper;
import top.heliming.youyou.item.pojo.Category;
import top.heliming.youyou.item.service.CategoryService;

/**
 * description: //TODO
 *
 * @author: heliming
 * @date:2019/05/26 下午 9:42
 */
  @Service
  public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> queryListByParent(Long pid) {
      Category category = new Category();
      category.setParentId(pid);
      return this.categoryMapper.select(category);
    }

  @Override
  public List<Category> queryByBrandId(Long bid) {
    return this.categoryMapper.queryByBrandId(bid);
  }

  @Override
  public List<String> queryNameByIds(List<Long> ids) {
    return this.categoryMapper.selectByIdList(ids).stream().map(Category::getName).collect(Collectors
        .toList());}

  @Override
  public List<Category> queryAllByCid3(Long id) {
    Category c3 = this.categoryMapper.selectByPrimaryKey(id);
    Category c2 = this.categoryMapper.selectByPrimaryKey(c3.getParentId());
    Category c1 = this.categoryMapper.selectByPrimaryKey(c2.getParentId());
    return Arrays.asList(c1,c2,c3);
  }
  }
